package com.cskaoyan.market.controller;

import com.cskaoyan.market.db.domain.MarketAddress;
import com.cskaoyan.market.service.MarketAddressService;
import com.cskaoyan.market.service.MarketAddressServiceImpl;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author: YaLiFeng
 * @description: TODO
 * @date: 2024/5/6 17:26
 */
@RestController
@RequestMapping("/admin/address")
@WebServlet("/admin/address/*")
public class AdminAddressController extends HttpServlet {
    @Autowired
    MarketAddressService marketAddressService;
    @GetMapping("list")
    public Object list(String page,String limit,String sort,String order,String name,String userId) throws IOException {

        String sortParam =sort;
        String orderParam = order;
        Integer pageParam=null;
        Integer limitParam=null;
        try {
            pageParam = Integer.parseInt(page);
            limitParam = Integer.parseInt(limit);
        } catch (NumberFormatException e) {
            Object object = ResponseUtil.badArgument();
            String s = JacksonUtil.getObjectMapper().writeValueAsString(object);
            return ResponseUtil.fail();
        }
        List<MarketAddress> marketAddressList=marketAddressService.list(limitParam,pageParam,sortParam,orderParam,name,userId);
        return ResponseUtil.okList(marketAddressList);


    }

}
